18
Beginner’s Guide to Code Algorithms
18
You can easily refer to a cell in your spreadsheet using the “Cells” function. The
numbers in parenthesis refer to the row and the column. Row 1 column 1 is the cell
A1 and is referred to as Cells(1,1) in the program.
Checking for a string value (alphabets or a combination of alphabets, special char
acters and numbers) requires the use of quotation marks. You do not need them if you
are checking for numbers.
But the code is not complete. It can only detect the first column. It can only detect
the “X”, not the “O”.
You can easily build on this code to check all columns, rows, and diagonals. If you
think about it for a second, there are eight possibilities for winning for each player
(three rows, three columns, and two diagonals). Hence 16 variations. You therefore
need to add 15 additional statements like the one above to complete the game.
While this is fun and can be easily accomplished, there are a few drawbacks:
• It lacks visual appeal
• You have to know that the game should only be played in rows 1 to 3 and col
umns 1 to 3
• You need another player to play it
• Once a game is done you have to manually clean out the cells before you can
play another one
• You cannot keep score
• You cannot easily extend the logic to more than a 3 × 3 matrix
This is why you need more sophisticated techniques.
Let us solve the first problem first. The visual appeal is also known as a “user inter
face” in computer jargon.
I am going to show you how to build something like this that looks much prettier.
FIGURE 2.13 Tic Tac Toe user interface.